<?php

namespace ltcms\response;

class ViewManage
{
    private static $_instance;
    private function __construct(){}
    private function __clone(){ }

    protected $vars=array();

    /**
     * 获取类对象
     */
    public static  function getInstance(){
        if(!(self::$_instance instanceof self)){
            self::$_instance=new self();
        }
        return self::$_instance;
    }

    /**
     * 模板变量赋值
     * @param $name
     * @param null $value
     * @return $this
     */
    public function assign($name, $value = null)
    {
        if (is_array($name)) {
            $this->vars = array_merge($this->vars, $name);
        } else {
            $this->vars[$name] = $value;
        }
        return $this;
    }

    /**
     * 获取视图变量
     * @param null $name
     * @return array|mixed|null
     */
    public function getVars($name = null)
    {
        if (is_null($name)) {
            return $this->vars;
        } else {
            return $this->vars[$name] ?? null;
        }
    }
}
